//
//  YKRecommendTagController.m
//  百思不得姐
//
//  Created by Eric.Wu on 16/2/26.
//  Copyright © 2016年 Eric.Wu. All rights reserved.
//

#import "YKRecommendTagController.h"
#import "YKRecommendTagCell.h"
#import "AFHTTPSessionManager.h"
#import <MJExtension.h>
#import <SVProgressHUD.h>
#import "YKRecommmendTag.h"
@interface YKRecommendTagController ()
@property (nonatomic,strong) NSArray *recommend;

@end

@implementation YKRecommendTagController
static NSString *const cellID = @"recommendTag";
- (void)viewDidLoad {
    [super viewDidLoad];
    self.tableView.rowHeight = 70;
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.view.backgroundColor = YKGlobalBg;
//    加载数据
    [self loadTags];
}
#pragma mark - 发请求加载数据
- (void)loadTags
{
    [SVProgressHUD showSuccessWithStatus:@"正在加载用户数据" maskType:SVProgressHUDMaskTypeBlack];
    
    [self.tableView registerNib:[UINib nibWithNibName:NSStringFromClass([YKRecommendTagCell class]) bundle:nil] forCellReuseIdentifier:cellID];
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    
    params[@"a"] = @"tag_recommend";
    params[@"action"] = @"sub";
    params[@"c"] = @"topic";
//    @"http://api.budejie.com/api/api_open.php"
    [[AFHTTPSessionManager manager] GET:@"http://api.budejie.com/api/api_open.php" parameters:params success:^(NSURLSessionDataTask *task, id responseObject) {
//        YKLog(@"%@",responseObject);
        self.recommend = [YKRecommmendTag objectArrayWithKeyValuesArray:responseObject];
//        YKLog(@"%@",responseObject[@"list"]);
        [SVProgressHUD dismiss];
        [self.tableView reloadData];
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        [SVProgressHUD dismiss];
        YKLog(@"%@",error);
    }];

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source



- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    return self.recommend.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    YKRecommendTagCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    cell.recommendTag = self.recommend[indexPath.row];
    return cell;
}


/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    } else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}
*/

/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
}
*/

/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
